<?php
	require_once "../include/global.php";
	require_once "../add/TegGenerator.php";
?>
<!--[if IE]>
<!DOCTYPE PUBLIC html>
<script language='JavaScript'> 
		window.location.href = 'http://web/stat_in4/php/monitor/index.php'
		</script>
<![endif]-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link href="../../css/convert.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery-1.6.2.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../js/jquery-ui-1.8.16.custom.min.js"></script>
    <script type="text/javascript" language="javascript" src="../..js/jquery.maskedinput-1.2.2.min.js"></script>
	<script type="text/javascript" src="http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/jquery.ui.datepicker-ru.js"></script>
		
		<script src="../../js/monitor.js" type="text/javascript"></script>
		<script src="../../js/my_lib.js" type="text/javascript"></script>
		<link type="text/css" href="../../css/monitor.css" rel="stylesheet" />	
		<link type="text/css" href="../../css/button.css" rel="stylesheet" />	
		
	<title>Статистика по входящим</title>
	<link rel="stylesheet" type="text/css" href="../../tabs/styles.css" />
	<script type="text/javascript" src="../../tabs/script.js"></script>
	<link type="text/css" href="../../css/ui-lightness/jquery-ui-1.8.16.custom.css" rel="stylesheet" />	
	<style type="text/css">
		/*demo page css*/
		body{ font: 62.5% "Trebuchet MS", sans-serif; }
		.demoHeaders { margin-top: 2em; }
		#dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;}
		#dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;}
		ul#icons {margin: 0; padding: 0;}
		ul#icons li {margin: 2px; position: relative; padding: 4px 0; cursor: pointer; float: left;  list-style: none;}
		ul#icons span.ui-icon {float: left; margin: 0 4px;}
	</style>
	<script type="text/javascript" language="javascript">
	$(function($){
		//$( "#from, #to" ).datepicker.setDefaults($( "#from, #to" ).datepicker.regional['ru']);
		var dates = $( "#from, #to" ).datepicker({
			defaultDate: "+1w",
			changeMonth: true,
			numberOfMonths: 3,
			dateFormat: "yy-mm-dd",
			onSelect: function( selectedDate ) {
				var option = this.id == "from" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" ),
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		});
		$("#from, #to").datepicker($.datepicker.regional['ru']);
		//dates.datepicker( "option", $.datepicker.regional[ "fr" ] );
		setInterval(function(){
			$.post('../include/global.php', {variable:'stat_in_processing'},//передали
			function(data)
			{
				if (data=='true')
				{
					$( "#progressbar" ).show();
					$.post('../include/global.php', {variable:'stat_in_converter'},//передали
					function(data)
					{
						var val = parseInt(data);
						$( "#progressbar" ).progressbar({
							value: val
						});
					});
				}
				else
				{
					$( "#progressbar" ).hide();
				}
			});
		}, 100);
		$('#form_queue').submit(function(){
			var tosend = $(this).serialize();
			$.post('../../convert/test_s.php', tosend, function(data) {
				$('#result').html(data);
				$('#to_firm').show();
				//alert('finish');
				window.location.reload();
			});
			return false;
		})
		
		$('#chk_minup').live('click',function(){
			$('#plain').toggle();
			$('#minup').toggle();
		})
		//btn_setperiod('monthbegin','date');
	})
	
	btn_setperiod = function(from_,to_){
		$('[name="db[queue_from]"]').val(getDatetime(from_));
		$('[name="db[queue_to]"]').val(getDatetime(to_));
	}
	
	getDatetime = function(k_){//k_ = [''|'date'|'time'] 
		//получение даты (сегодняшний день) вида DATETIME MySQL 
		//без ключа yyyy-mm-dd hh:mm:ss
		//ключ date только yyyy-mm-dd
		//ключ time только hh:mm:s
		var add0 = function(val_){val_+='';val_.length==1?val_='0'+val_:val_;return val_;}
		var date = new Date();
		var day = add0(date.getDate());
		var month = add0((date.getMonth()+1));
		var year = add0(date.getFullYear());
		var hour = add0(date.getHours());
		var min  = add0(date.getMinutes());
		var sec  = add0(date.getSeconds());
		
		switch(k_){
			case 'date':
				return year+'-'+month+'-'+day;	
			case 'time':
				return hour+':'+min+':'+sec;
			case 'ms':
				return hour+':'+min+':'+sec + '.' + date.getMilliseconds();
			case 'daybegin':
				return year+'-'+month+'-'+day+' 00:00:00';
			case 'dayend':
				return year+'-'+month+'-'+day+' 23:59:59';
			case 'monthbegin':
				return year+'-'+month+'-01';
			default : return year+'-'+month+'-'+day+' '+hour+':'+min+':'+sec;
				
		}
	}
	</script>
</head>
<body>
<div id=converter>
<?php
		tabs();
?>

	<div id="div_queue">
		<form id="form_queue">
			<label for="from" style="font: 160% 'Times New Roman'"/>От</label>
			<?php
				$d1 = minday();
				echo '<input type="text" id="from" name="db[queue_from]" value="'.$d1.'">';
			?>
			<label for="to" style="font: 160% 'Times New Roman'">до</label>
			<?php
				$d2 = maxday();
				echo '<input type="text" id="to" name="db[queue_to]" value="'.$d2.'">';
			?>
			<input type="button" value="сегодня" class="button blue medium" style="font: 160% 'Times New Roman'" onclick="javascript:btn_setperiod('date','date');"/>
			<input type="button" value="данный месяц" class="button blue medium" style="font: 160% 'Times New Roman'" onclick="javascript:btn_setperiod('monthbegin','date');"/>
			<label style="font: 160% 'Times New Roman'"/>Норма обслуживания</label>
			<?php
				$q = getvar('QUALITY');
				if ($q=='')
					$q = 20;
				echo '<input type="text" class="seconds" name="opt[quality_sec]" value="'.$q.'" />';
			?>
			<?php
				$str = getvar('isminup');
				$attr = '';
				if ($str=='true')
					$attr = 'checked';
				else
					$attr = '';
				echo '<span id="to_firm" style="displya:none; font: 160% '.'Times New Roman'.'">Заказчику <input type="checkbox" name="opt[minup]" '.$attr.' id="chk_minup" /></span>';
			?>
			<input type="submit" class="button orange medium" value="Расчет" style="font: 160% 'Times New Roman'"/>
		</form>
		<div id="progressbar" style='height:10px'></div>
	</div>
	<?php
		$now = new DateTime("now");
		//echo $now->format('Y-m-d H:i:s');
		$dc = new DateTime(getvar('stat_in_last_convert'));
		//echo $dc->format('Y-m-d H:i:s');
		//echo 123;
		$interval = $now->diff($dc);
		//print_r($interval);
		if ($interval->d>0)
			echo $interval->format('Пересчитано %d дней назад');
			else
				if ($interval->h>0)
					echo $interval->format('Пересчитано %h часов назад');
				else
					if ($interval->i>0)
						echo $interval->format('Пересчитано %i минут назад');
					else
						if ($interval->s>0)
							echo $interval->format('Пересчитано %s секунд назад');
					
	?>
	<div id="result">
	</div>
	
	</div>
	<?php
		require_once "modul.php";
	?>
</body>
</html>